using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPageAdmin : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["AdminName"] != null)
            {
                lblName.Text = Session["AdminName"].ToString();
                if ((string)Session["Authority"] == "Admin")
                {
                    lblName.NavigateUrl = "~/Admin/AdminCP.aspx";
                    this.refreshOrders();
                    this.refreshModified();
                }
                else 
                {
                    lblName.NavigateUrl = "";
                }
            }
            else
                Response.Redirect("Default.aspx");
        }

    }

    public void refreshOrders()
    {
        string sql = string.Format(@"
                                        SELECT
                                            b.OrderID,
                                            a.FullName,
                                            a.SDT,
                                            b.NgayDat,
                                            b.NgayNhan,
                                            b.NoiNhan,
                                            b.TrangThai 
                                        FROM
                                            customers a INNER JOIN Orders b 
                                                        ON a.CustomerID = b.CustomerID,
                                            QuanTri qt
                                        WHERE b.NgayDat>qt.LastLog AND qt.ID=N'{0}'
                                        Order by b.NgayDat DESC
                                        ", Session["AdminName"].ToString());

        DataTable dtb = new DataTable();
        dtb = DataBase.GetDataTable(sql);
        if (dtb.Rows.Count > 0)
        {
            hlNew.Visible = true;
        }
        else
            hlNew.Visible = false;
    }

    public void refreshModified()
    {
        string sql = "SELECT Modified FROM QuanTri WHERE ID=@ID";
        DataTable dt = DataBase.GetDataTable(sql, "@ID", lblName.Text);
        if (dt.Rows[0][0].ToString() == "1")
        {
            hlNotification.Visible = true;
        }
        else
            hlNotification.Visible = false;
    }

    protected void btnExit_Click(object sender, ImageClickEventArgs e)
    {
        Session["AdminName"] = null;
        Session["Authority"] = null;
        Response.Redirect("Default.aspx");        
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("HangXe.aspx");
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Model.aspx");
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("SanPham.aspx");
    }
    protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("KhachHang.aspx");
    }
    protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("DonHang.aspx");
    }
    protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("BaoCao.aspx");
    }
}
